/**
 *  @file
 *  @brief   箱形1（BOX1）梁截面属性使用解析公式计算类
 *  @author  duweixing
 *  @date    2024.04.22
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "Box1SectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::Box1SectionFormulaCalculator;

void Box1SectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real b{section.m_dimension[0]};
    Real h{section.m_dimension[1]};
    Real t1{section.m_dimension[2]};
    Real t2{section.m_dimension[3]};
    Real t3{section.m_dimension[4]};
    Real t4{section.m_dimension[5]};
    Real bi{b - t3 - t4};
    Real hi{h - t1 - t2};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = b * h - bi * hi;
    // Real yS = 0.0;  // ToDo
    // Real zS = 0.0;  // ToDo
    Real yC = (b * t2 * 0.5 * t2 + b * t1 * (h - 0.5 * t1) + hi * (t3 + t4) * (t2 + 0.5 * hi)) / property.m_A;
    Real zC = (h * t4 * 0.5 * t4 + h * t3 * (b - 0.5 * t3) + bi * (t1 + t2) * (t4 + 0.5 * bi)) / property.m_A;
    property.m_I1  = bi * (t1 * t1 * t1 + t2 * t2 * t2) / 12.0 + bi * t1 * (h - 0.5 * t1 - yC) * (h - 0.5 * t1 - yC) +
                     bi * t2 * (yC - 0.5 * t2) * (yC - 0.5 * t2) + (t3 + t4) * h * h * h / 12.0 +
                     h * (t3 + t4) * (yC - 0.5 * h) * (yC - 0.5 * h);
    property.m_I2  = (t1 + t2) * b * b * b / 12.0 + b * (t1 + t2) * (0.5 * b - zC) * (0.5 * b - zC) +
                     hi * (t3 * t3 * t3 + t4 * t4 * t4) / 12.0 + hi * t3 * (b - 0.5 * t3 - zC) * (b - 0.5 * t3 - zC) +
                     hi * t4 * (zC - 0.5 * t4) * (zC - 0.5 * t4);
    property.m_I12 = b * t1 * (h - 0.5 * t1 - yC) * (0.5 * b - zC) + b * t2 * (0.5 * t2 - yC) * (0.5 * b - zC) +
                     hi * t3 * (0.5 * hi + t2 - yC) * (b - 0.5 * t3 - zC) + hi * t4 * (0.5 * hi + t2 - yC) * (0.5 * t4 - zC);
    property.m_J   = 4.0 * (b - 0.5 * (t3 + t4)) * (h - 0.5 * (t1 + t2)) * (b - 0.5 * (t3 + t4)) * (h - 0.5 * (t1 + t2)) /
                     ((h - 0.5 * (t1 + t2)) * (t3 + t4) / (t3 * t4) + (b - 0.5 * (t3 + t4)) * (t1 + t2) / (t1 * t2));
    property.m_K1  = hi * (t3 + t4) / property.m_A;
    property.m_K2  = bi * (t1 + t2) / property.m_A;
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({-yC + h, -zC + b,
                               -yC,     -zC + b,
                               -yC,     -zC,
                               -yC + h, -zC});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}